<template>
    <div class="assignment-header">
        <button class="back-button" @click="$router.go(-1)">← 聊天室</button>
    </div>
    <div class="chat_room">
        <div class="chat_left">
            <div class="chat_left1">
                <img src="@/assets/images/usagi1.jpg" alt="avatar" class="usertouxiang">
                <div class="user_name">当前用户</div>
                <!-- <img src="@/assets/images/xiaoxi.jpg" alt="avatar" class="xiaoxi"> -->
            </div>
            <div class="chat_left2">
                <div class="chat_left21">
                    <div class="username">聊天室</div>
                </div>
                <div class="chat_left21">
                    <img src="@/assets/images/yonghutouxiang.png" alt="avatar" class="avatar-icon1">
                    <div class="username">小毛小毛</div>
                </div>
                <div v-for="user in users" :key="user.id" class="chat_left21" id="user.id">
                    <img src="@/assets/images/yonghutouxiang2.png" alt="avatar" class="avatar-icon1">
                    <div class="username">{{ user.name }}</div>
                </div>

            </div>
        </div>
        <div class="chat_right">
            <div class="chat_right1">
                <div class="username">聊天室</div>
            </div>
            <div class="chat_right2">
                <div class="messages">
                    <div class="message1"> 
                        <img src="@/assets/images/aislogo.png" alt="avatar" class="avatar-icon">
                        <div class="message-content">
                            <span class="user">欢迎来到聊天室</span>
                        </div>
                        <br>
                    </div>
                    <div v-for="(message, index) in messages" :key="index" class="message21">
                        <img :src="message.avatar" alt="avatar" class="avatar-icon2">
                        <div class="message-content2">
                            <span :class="{ 'user': message.user === 'you', 'other': message.user !== 'you' }">
                                {{ message.text }}
                            </span>
                        </div>
                        <br>
                        <br>
                    </div>
                </div>
                <div class="input-area">
                    <el-input v-model="newMessage" placeholder="请输入内容" @keyup.enter="sendMessage" class="input-box" />
                    <el-button type="primary" @click="sendMessage">发送</el-button>
                </div>
            </div>
        </div>
         <!-- 聊天室右边功能 -->
         <div class="chat_function">
            <div class="function1">
                <span class="function2_text">课堂管理</span><br>
                <div style="margin-top: 3lvh; text-align: center;">
                    <el-button type="primary" @click="">签到</el-button>
                    <el-button type="primary" @click="">填写问卷</el-button>
                    <el-button type="primary" @click="">课堂总结</el-button>
                </div> 
            </div>
            <div class="function2">
                <span class="function2_text">课程教学计划</span>
                <div class="timeline">
      <div class="event" v-for="(event, index) in events" :key="index">
        <div class="event-time">{{ event.time }}</div>
        <div class="event-line"></div>
        <div class="event-content">{{ event.content }}</div>
      </div>
    </div>
            </div>
        </div>
       
    </div>
</template>
<script setup>
import { ref, computed } from 'vue';
import { useRouter } from 'vue-router';
import userAvatar from '@/assets/images/usagi2.png'; // 确保这是正确的头像路径

const router = useRouter();
const users = ref([
    // 假设从后端获取的用户列表
    { id: 1, name: '用户A', avatar: 'path/to/avatarA.png' },
    { id: 2, name: '用户B', avatar: 'path/to/avatarB.png' },
    { id: 2, name: '用户B', avatar: 'path/to/avatarB.png' },
    { id: 2, name: '用户B', avatar: 'path/to/avatarB.png' },
    { id: 2, name: '用户B', avatar: 'path/to/avatarB.png' }
]);

const dropdownVisible = ref(false);
const toggleDropdown = () => {
    dropdownVisible.value = !dropdownVisible.value;
};

const messages = ref([
    { user: 'you', text: '欢迎来到聊天室', avatar: userAvatar },
]);

const newMessage = ref('');

const sendMessage = () => {
    const currentTime = new Date().toLocaleTimeString();
    messages.value.push({
        user: 'you',
        text: newMessage.value,
        avatar: userAvatar,
        timestamp: currentTime
    });
    newMessage.value = '';
};

const Questionnaire = () => {
    ElMessage.success('发布问卷成功');
};

const events = ref([
  { time: '08:00', content: '上课' },
  { time: '08:30', content: '签到' },
  { time: '09:00', content: '填写问卷' },
  { time: '11:30', content: '下课' }
]);
</script>

<style scoped>
.assignment-header {
    display: flex;
    height: 7lvh;
    width: 99lvw;
    background-color: #13227A;
    color: white;
}

.back-button {
    background-color: transparent;
    margin-left: 1%;
    width: 7%;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
}

.back-button:hover {
    color: #d72d2d;
}

.chat_room {
    float: left;
    display: flex;
    height: 89lvh;
    width: 66lvw;
    border: 1px solid #eee;
    border-radius: 4px;
    margin-top: 1lvh;
    margin-left: 0.2lvw;
    background-color: #b9b9b9;
}

.chat_left {
    float: left;
    width: 15.6lvw;
    background-color: #b9b9b9;
}

.chat_left1 {
    float: left;
    display: flex;
    flex-direction: row;
    height: 9lvh;
    width: 15.6lvw;
    background-color: #f8f8f8;
}

.usertouxiang {
    float: left;
    width: 8lvh;
    height: 8lvh;
    margin-top: 0.5lvh;
    margin-left: 0.5lvh;
    border-radius: 50%;
}

.user_name {
    margin-left: 10px;
    margin-top: 35px;
    font-size: 18px;
    color: #7c7c7c;
}

/* .xiaoxi{
    float: left;
    width: 7lvh;
    height: 7lvh;
    margin-top: 13px;
    margin-left: 33px;
} */

.chat_left2 {
    float: left;
    flex-direction: column;
    height: 79.8lvh;
    width: 15.6lvw;
    margin-top: 0.2lvh;
    max-height: 89lvh;
    overflow-y: auto;
    background-color: #f8f8f8;
}

.chat_left21 {
    float: left;
    height: 7lvh;
    width: 15.6lvw;
    background-color: #ffffff;
    display: flex;
    flex-direction: row;
    border: 0px solid #2084ff;
    border-bottom: 2px solid #b9b9b9;
}

.chat_left21:hover {
    background-color: #2084ff;
}

.avatar-icon1 {
    width: 5.5lvh;
    height: 5.5lvh;
    margin-top: 0.5lvh;
    margin-left: 0.5lvh;
    border-radius: 50%;
}

.username {
    margin-left: 5px;
    margin-top: 15px;
    font-size: 22px;
}

.chat_message {
    margin-bottom: 10px;
    padding: 10px;
    background-color: #f8f8f8;
    border-radius: 5px;
}

.chat_message span {
    color: #333;
}

.chat_right {
    float: left;
    height: 89lvh;
    width: 50.2lvw;
    margin-left: 0.1lvw;
}

.chat_right1 {
    float: left;
    height: 9lvh;
    width: 50.2lvw;
    background-color: #f8f8f8;
}

.chat_right2 {
    float: left;
    height: 79.6lvh;
    width: 50.2lvw;
    margin-top: 0.2lvh;
    background-color: #f8f8f8;
}

.messages {
    flex: 1;
    max-height: 70.6lvh;
    overflow-y: auto;
    padding: 10px;
}

.message1 {
    margin-bottom: 10px;
}

.message21 {
    margin-bottom: 10px;
    overflow: hidden;
}

.message-content {
    display: flex;
    float: left;
    max-width: 60%;
    margin-left: 1px;
}

.message-content2 {
    float: right;
    max-width: 60%;
    border-radius: 50%;
}
.user {
    background-color: #ffffff;
    color: rgb(47, 45, 45);
    padding: 5px 10px;
    border-radius: 5px;
    margin-right: 5px;
    /* border: 1px solid #1c1a48; */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.other {
    background-color: #f9f9f9;
    color: #333;
    padding: 5px 10px;
    border-radius: 5px;
    margin-left: 5px;
}

.input-area {
    display: flex;
    align-items: center;
    margin-top: 90lvh;
    margin-left: 14.8lvw;
    position: fixed;
    top: 20px;
    left: 30px;
}

.input-box {
    flex: 1;
    width: 45.3lvw;
    margin-right: 10px;
}

.el-button {
    padding: 5px 10px;
}

.avatar-icon {
    width: 30px;
    float: left;
    height: 30px;
    border-radius: 50%;
    margin-right: 10px;
    /* 头像与消息文本之间的间距 */
}

.avatar-icon2{
    width: 30px;
    float: right;
    height: 30px;
    border-radius: 50%;
    margin-right: 1px;
    margin-left: 6px;
}

.message-content {
    display: flex;
    align-items: flex-start;
    /* 消息内容与头像之间的间距 */
}

.chat_function {
    float: left;
    width: 32.8lvw; 
}

.function1{
    float: left;
    height: 17lvh;
    padding-top: 1lvh;
    max-height: 17lvh;
    overflow-y: auto;
    width: 32lvw;
    border: #d6d6d6 1px solid;
    margin-left: 0.4lvw;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.function2{
    float: left;
    height: 41lvh;
    width: 32lvw;
    padding-top: 1lvh;
    max-height: 41lvh;
    overflow-y: auto;
}

.function2_text{
    color: #1b2f3d;
    font-size: 24px;
    font-family: kaiti;
    margin-left: 1lvw;
}

.timeline {
  position: relative;
}

.event {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.event-time {
  position: absolute;
  left: 25px;
  font-size: 14px;
  color: #888;
}

.event-line {
  position: absolute;
  left: 85px;
  top: 5px;
  bottom: -10px;
  width: 2px;
  background-color: #409EFF;
}

.event-content {
  padding: 5px 10px;
  background-color: #f8f8f8;
  border-radius: 5px;
  color: #333;
  margin-left: 110px;
}

.recording1 {
    position: absolute;
    top: 71lvh;
    left: 67lvw;
    height: 5lvh;
    width: 32.8lvw;
    text-align: center;
}
.recording2 {
    position: absolute;
    top: 76lvh;
    left: 67lvw;
    height: 22lvh;
    width: 32.8lvw;
    text-align: center;
    border: #d6d6d6 1px solid;
}
</style>